package cn.gx.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Service;

import cn.gx.dao.BaseDao;
import cn.gx.domain.User;
import cn.gx.service.UserService;
import cn.gx.util.DataUtil;
import cn.gx.util.ValidateUtil;

@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

	/**
	 * 重写该方法，覆盖注解
	 */
	@Resource(name="userDao")
	public void setDao(BaseDao dao) {
		super.setDao(dao);
	}

	public boolean isRegisted(String email) {
		String hql="from User u where u.email=?";
		List<User> userList = this.findEntityByHQL(hql, email);
		
		return ValidateUtil.isValid(userList);
	}

	public User login(String email, String password) {
		password=DataUtil.md5(password);
		String hql="from User u where u.email=? and u.password=?";
		
		List<User> userList = this.findEntityByHQL(hql, email,password);
		return ValidateUtil.isValid(userList)?userList.get(0):null;
	}

	
	
}
